home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 19 / madtrb14.zip / NINV2.PAS < prev    next >
Pascal/Delphi Source File  |  1985-05-17  |  3KB  |  56 lines

  1. (*-------------------------------------------------------------------------*)
  2. (*          Ninv2 -- Find Percentage Point of Normal Distribution          *)
  3. (*-------------------------------------------------------------------------*)
  4.  
  5. FUNCTION Ninv2( P : REAL ) : REAL;
  6.  
  7. (*-------------------------------------------------------------------------*)
  8. (*                                                                         *)
  9. (*       Function:  Ninv2                                                  *)
  10. (*                                                                         *)
  11. (*       Purpose:   Finds percentage point of normal distribution          *)
  12. (*                  (high accuracy)                                        *)
  13. (*                                                                         *)
  14. (*       Calling Sequence:                                                 *)
  15. (*                                                                         *)
  16. (*            Perc  := Ninv2( P : REAL ) : REAL;                           *)
  17. (*                                                                         *)
  18. (*                 P      --- input probability                            *)
  19. (*                 Perc   --- resultant percentage point                   *)
  20. (*                                                                         *)
  21. (*       Calls:   Ninv                                                     *)
  22. (*                                                                         *)
  23. (*       Remark:  This method provides about 12-13 decimal digits of       *)
  24. (*                accuracy.  The method used is to improve the             *)
  25. (*                approximation produced by NINV using a Taylor series     *)
  26. (*                on the approximation error.                              *)
  27. (*                                                                         *)
  28. (*-------------------------------------------------------------------------*)
  29.  
  30. VAR
  31.    Xp:    REAL;
  32.    P1:    REAL;
  33.    Z:     REAL;
  34.    X3:    REAL;
  35.    X2:    REAL;
  36.    X1:    REAL;
  37.    Phi:   REAL;
  38.  
  39. BEGIN (* Ninv2 *)
  40.  
  41.    Xp     := Ninv( P );
  42.  
  43.    P1     := SigNorm( Xp );
  44.  
  45.    Phi    := SQRT( 1.0 / ( 2.0 * PI ) ) * EXP( -( Xp * Xp ) / 2.0 );
  46.  
  47.    Z      := ( P - P1 ) / Phi;
  48.  
  49.    X3     := ( 2.0 * ( Xp * Xp ) + 1.0 ) * Z / 3.0;
  50.    X2     := ( X3 + Xp ) * Z / 2.0;
  51.    X1     := ( ( X2 + 1.0 ) * Z );
  52.  
  53.    Ninv2  := Xp + X1;
  54.  
  55. END   (* Ninv2 *);
  56.